﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KZ.Express.H.Presenter;
using KZ.Express.H.ENT;
using KZ.Utilities;

namespace KZ.Express.H.Orders
{
    public partial class StatisticalListView : BaseView
    {
        private void StatisticalListView_Load(object sender, EventArgs e)
        {
            dtpFrom.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            dtpTo.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(1).AddDays(-1);
        }

        public StatisticalListView()
        {
            InitializeComponent();
            Initialize(dtgStatistical);

            _presenter = new BasePresenter(this);

            this.ActionName = String.Empty;
            this.dtgStatistical.Sorted += new EventHandler(Datagrid_Sorted);
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            SearchCriteria search = new SearchCriteria();
            search.Add("From", dtpFrom.Value);
            search.Add("To", dtpTo.Value);
            DataTable dt = _presenter.LoadDataTable(OrderENT.SelectStatisticalProcedure, search);
            _bindingSource.DataSource = dt;
            lblTotalRate.Text = Utility.CurrencyParse(dt.Compute("SUM(Amount)", String.Empty));
        }
    }
}
